<?php

class ActicleController extends Controller
{
	public function filters()
	{
		return array(
			'rights', // perform access control for CRUD operations

		);
	}
	public function allowedActions()
	{
		return '*';
	}
	public function actionIndex($alias=null)
	{
		$this->layout = 'main_two';
		$criteria = new CDbCriteria();
		$criteria->with = array('ActicleCategories');
		$criteria->order = "t.id DESC";
		if($alias == null){
			$category = ActicleCategories::model()->findByPk(5);
			if($category == null){
				throw new CHttpException(404,Yii::app()->params['error']['404']);
			}
			$criteria->condition = 'ActicleCategories.parent = 5';
		}else{
			$category = ActicleCategories::model()->findByAttributes(array('alias'=>$alias));
			if($category == null){
				throw new CHttpException(404,Yii::app()->params['error']['404']);
			}
			$criteria->condition = 'ActicleCategories.alias = :alias';
			$criteria->params = array(':alias'=>$alias);
			$this->currentCategory = $category->id;
		}
		$total = Acticles::model()->count($criteria);
		$pages = new CPagination($total);
		$pages->pageSize = 10;
		$pages->applyLimit($criteria);
		$model = Acticles::model()->findAll($criteria);
		$this->pageTitle = "Ngữ pháp - ".$this->title;
		$this->render('index',compact('model','category','pages'));
	}
	public function actionDetail($alias=null){
		$model = Acticles::model()->findByAttributes(array('alias'=>$alias));
		if($model == null){
			throw new CHttpException(404,Yii::app()->params['error']['404']);
		}
		$this->pageTitle = $model->name." - ".$this->title;
		$this->render('detail',compact('model'));
	}
}